﻿using System;
using System.Collections.Generic;
using System.Text;

using NGE;

namespace MH.MENU
{

    public class CHRInfo:Panelbox
    {
        public CHRInfo(Game g)
            : base(g)
        {
            Name = "人物信息";

            binfo = new Textbox();
            binfo.Location = new Microsoft.DirectX.Vector3(10, 10, 0);
            binfo2 = new Textbox();
            binfo2.Location = new Microsoft.DirectX.Vector3(10, 80, 0);

            AddElement(binfo);
            AddElement(binfo2);

            this.OnPanelboxOpen += new MenuEvent(InfoCHR_OnPanelboxOpen);
            this.OnPanelboxRefresh += new MenuEvent(InfoCHR_OnPanelboxRefresh);

            Weapon = new Buttonbox();
            Weapon.Location = new Microsoft.DirectX.Vector3(140, 110, 0);
            Weapon.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);

            Head = new Buttonbox();
            Head.Location = new Microsoft.DirectX.Vector3(140, 130, 0);
            Head.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);

            Body = new Buttonbox();
            Body.Location = new Microsoft.DirectX.Vector3(140, 150, 0);
            Body.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);

            Leg = new Buttonbox();
            Leg.Location = new Microsoft.DirectX.Vector3(140, 170, 0);
            Leg.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);

            Hand = new Buttonbox();
            Hand.Location = new Microsoft.DirectX.Vector3(140, 190, 0);
            Hand.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);

            Foot = new Buttonbox();
            Foot.Location = new Microsoft.DirectX.Vector3(140, 210, 0);
            Foot.OnButtonboxEvent += new MenuEvent(bb_OnButtonboxEvent);


            AddElement(Weapon);
            AddElement(Head);
            AddElement(Body);
            AddElement(Leg);
            AddElement(Hand);
            AddElement(Foot);
        }

        void bb_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                if (((Buttonbox)sender).Location.Y == 110)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Weapon);
                }
                else if (((Buttonbox)sender).Location.Y == 130)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Head);
                }
                else if (((Buttonbox)sender).Location.Y == 150)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Body);
                }
                else if (((Buttonbox)sender).Location.Y == 170)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Leg);
                }
                else if (((Buttonbox)sender).Location.Y == 190)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Hand);
                }
                else if (((Buttonbox)sender).Location.Y == 210)
                {
                    scriptCOM.AS(chr_name + " unequip " + PropType.Foot);
                }
                scriptCOM.AS("menu refresh " + Name + " " + chr_name);
            }
        }

        string chr_name;

        void InfoCHR_OnPanelboxRefresh(object sender, object arg)
        {
            chr_name = arg.ToString();
            Character chr = sceneCOM.GetCHR(chr_name);
            string str = "";
            string str2 = "";
            str += "名字：" + chr.Name + "\n";
            str += "等级：" + chr.LVL + "\n";
            str += "经验：" + chr.EXP + "\n";
            str += "钱包：" + chr.G + "G\n";


            str2 += "HP：" + chr.HP + "/" + chr.HPMax + "\n";
            str2 += "伤害：" + chr.Damage + "\n";
            str2 += "防御：" + chr.Defense + "\n";
            str2 += "命中：" + chr.Accurate + "\n";
            str2 += "躲避：" + chr.Missrate + "\n";
            str2 += "攻击范围：" + chr.AttackRangeMin + "-" + chr.AttackRangeMax + "\n";

            binfo.Text = str;
            binfo2.Text = str2;

            Weapon.Textbox.Text = "武器：" + chr.Weapon.Name;
            Head.Textbox.Text = "头部：" + chr.Head.Name;
            Body.Textbox.Text = "上身：" + chr.Body.Name;
            Leg.Textbox.Text = "下身：" + chr.Leg.Name;
            Hand.Textbox.Text = "手部：" + chr.Hand.Name;
            Foot.Textbox.Text = "脚部：" + chr.Foot.Name;
        }

        void InfoCHR_OnPanelboxOpen(object sender, object arg)
        {
            Refresh(sender, arg);
        }
        SceneComponent sceneCOM
        {
            get
            {
                return ((SceneComponent)game.GetComponent("SceneCOM"));
            }
        }
        ScriptComponent scriptCOM
        {
            get
            {
                return ((ScriptComponent)game.GetComponent("ScriptCOM"));
            }
        }

        Textbox binfo;
        Textbox binfo2;

        Buttonbox Weapon;
        Buttonbox Body;
        Buttonbox Leg;
        Buttonbox Foot;
        Buttonbox Head;
        Buttonbox Hand;
    }
}
